package org.yly.game.rpggame.domain.model;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class UpgradeEntity extends Entity implements Upgrade {

	protected Map<PropertyName, CustomProperty> propertyMap; // 游戏基本属性
	
	protected int level; // 级别
	
	public UpgradeEntity(String id, Set<? extends CustomProperty> propertySet) {
		super(id);
		propertyMap = new HashMap<PropertyName, CustomProperty>();
		for (CustomProperty property : propertySet) {
			propertyMap.put(property.getName(), property);
		}
	}

	public void upgrade() {
		for (Object property : propertyMap.values()) {
			if (property instanceof UpgradeProperty) {
				((UpgradeProperty) property).upgrade(level);
			}
		}
		this.level++;
	}

	public int getLevel() {
		return level;
	}

	public Collection<CustomProperty> getPropertySet() {
		return propertyMap.values();
	}
	
	public CustomProperty getCustomProperty(PropertyName name) {
		return propertyMap.get(name);
	}

}
